﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{
    public class CLSMAESUSP
    {
        string mtpppa_sus, mtpsus_sus, observ_sus;
        long consec_sus;

        public string MTPPPA_SUS
        {
            get { return mtpppa_sus; }
            set { mtpppa_sus = value; }
        }

        public string MTPSUS_SUS
        {
            get { return mtpsus_sus; }
            set { mtpsus_sus = value; }
        }

        public string OBSERV_SUS
        {
            get { return observ_sus; }
            set { observ_sus = value; }
        }

        public long CONSEC_SUS
        {
            get { return consec_sus; }
            set { consec_sus = value; }
        }

        MDOgeneral mod=new MDOgeneral();

        public long Consecutivo()
        {            
            try
            {
                DataTable dt = new DataTable();
                string query = "select max(consec_sus)+1 as consec from maesusp where mtpppa_sus='" + MTPPPA_SUS + "'";
                dt=mod.consulta(query);
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0][0].ToString() == "")
                    {
                        return 1;
                    }
                    else
                    {
                        return System.Convert.ToInt64(dt.Rows[0][0].ToString());
                    }
                }
                return 1;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void Insertar()
        {
            try
            {
                if (OBSERV_SUS == "" || OBSERV_SUS==null)
                    OBSERV_SUS = " ";
                string query = "insert into maesusp(mtpppa_sus,consec_sus,mtpsus_sus,observ_sus) values ('" + MTPPPA_SUS + "'," + CONSEC_SUS + ",'" + MTPSUS_SUS + "','" + OBSERV_SUS + "')";
                mod.comando(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void Eliminar()
        {
            try
            {
                string query = "delete from maesusp where mtpppa_sus='" + MTPPPA_SUS + "'";                
                mod.comando(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void Actualizar()
        {

        }

        public DataTable Consultar()
        {            
            try
            {
                string query = "select mtpsus_sus,observ_sus from maesusp where mtpppa_sus='" + MTPPPA_SUS + "'";
                return mod.consulta(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
